#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ == taoyulong2018@gmail.com
# __time__ == 2023/3/6 17:42
# ===========================================
#       题目名称： 33. 搜索旋转排序数组
#       题目地址： https://leetcode.cn/problems/search-in-rotated-sorted-array/
#       题目描述： https://note.youdao.com/s/LWYgPSzT
# ===========================================


class Solution:
    def search(self, nums, target):
        """
            左右开弓算法
        """
        left, right, res = 0, len(nums) - 1, -1
        while left <= right:
            print(left, right)
            if nums[left] == target:
                res = left
                break
            if nums[right] == target:
                res = right
                break
            left += 1
            right -= 1
        return res


if __name__ == "__main__":
    s = Solution()
    print("nums = [4,5,6,7,0,1,2], target = 0 => ", s.search(nums=[4, 5, 6, 7, 0, 1, 2], target=0))  # 4
    print("nums = [4,5,6,7,0,1,2], target = 3 => ", s.search(nums=[4, 5, 6, 7, 0, 1, 2], target=3))  # -1
    print("nums = [1], target = 0 => ", s.search(nums=[1], target=0))  # -1
